import axios from './axios.js';
const HTTP_PREFIX = 'api/map/api/v1'  //这里多加了一个api是因为用了脚手架的代理，详细见vue.cofig.js

/**
 * 禁飞区
 */
// 添加禁飞区
export const addNoFlyZone = async function (body){
    const url = `${HTTP_PREFIX}/no_fly_zone/add`
    const result = await axios.post(url,body)
    return result.data
  }
// 获取禁飞区
 export const searchNoFlyZone = async function (){
    const url = `${HTTP_PREFIX}/no_fly_zone/search`
    const result = await axios.get(url)
    return result.data
  }

// 删除禁飞区
  export const delNoFlyZone = async function (id){
    const url = `${HTTP_PREFIX}/no_fly_zone/delete/${id}`
    const result = await axios.delete(url)
    return result.data
  }
// 更新禁飞区
  export const updateNoFlyZone = async function (id,body){
    const url = `${HTTP_PREFIX}/no_fly_zone/update/${id}`
    const result = await axios.post(url,body)
    return result.data
  }
// 上传禁飞区
  export const uploadNoFlyZone = async function (config,body){
    const url = `${HTTP_PREFIX}/no_fly_zone/upload/`
    const result = await axios.post(url,body,config)
    return result.data
  }

/**
 * 上传凭证
 */
 export const uploadToken = async function (type){
  const url = `${HTTP_PREFIX}/manage/get_upload_sts/${type}`
  const result = await axios.get(url)
  return result.data
}

/**
 * 模型管理
 */
 export const modelDel = async function (id){
  const url = `${HTTP_PREFIX}/manage/remove_model/${id}`
  console.log('删除模型语句',url)
  const result = await axios.delete(url)
  return result.data
}
export const modelSearch = async function (params){
  let url = ''
  if(params.model_id==''){
      url = `${HTTP_PREFIX}/manage/search_models?unit=${params.unit}`
  }else{
      url = `${HTTP_PREFIX}/manage/search_models/?model_id=${params.model_id}`
  }
  const result = await axios.get(url)
  return result.data
}
export const modelAdd = async function (body) {
  const url = `${HTTP_PREFIX}/manage/add_model`
  const result = await axios.post(url,body)
  return result.data
}

export const modelUpdate = async function (body) {
  const url = `${HTTP_PREFIX}/manage/update_model`
  const result = await axios.post(url,body)
  return result.data
}

/**
 * tiles模型管理
 */
 export const tileDel = async function (id){
  const url = `${HTTP_PREFIX}/manage/remove_tile/${id}`
  console.log('删除模型语句',url)
  const result = await axios.delete(url)
  return result.data
}
export const tileSearch = async function (params){
  let url = ''
  if(params.tile_id==''){
      url = `${HTTP_PREFIX}/manage/search_tiles?unit=${params.unit}`
  }else{
      url = `${HTTP_PREFIX}/manage/search_tiles/?tile_id=${params.model_id}`
  }
  const result = await axios.get(url)
  return result.data
}
export const tileAdd = async function (body) {
  const url = `${HTTP_PREFIX}/manage/add_tile`
  const result = await axios.post(url,body)
  return result.data
}

export const tileUpdate = async function (body) {
  const url = `${HTTP_PREFIX}/manage/update_tile`
  const result = await axios.post(url,body)
  return result.data
}

/**
 * 地图管理
 */
export const mapSearch = async function (params){
  let url = ''
  if(params.map_id==''){
      url = `${HTTP_PREFIX}/manage/search_maps?unit=${params.unit}`
  }else{
      url = `${HTTP_PREFIX}/manage/search_maps/?map_id=${params.map_id}`
  }
  const result = await axios.get(url)
  return result.data
}
export const mapUploadData = async function (body) {
  console.log(body)
  const url = `${HTTP_PREFIX}/manage/add_map`
  const result = await axios.post(url,body)
  return result.data
}
export const mapPublish = async function (params) {
  const url = `${HTTP_PREFIX}/manage/publish/${params.map_id}/${params.status}`
  const result = await axios.get(url)
  return result.data
}
export const mapDelete = async function (map_id) {
  const url = `${HTTP_PREFIX}/manage/delete_map/${map_id}`
  const result = await axios.delete(url)
  return result.data
}

/** 正射影像管理*/
export const OrthophotoSearch = async function (params) {
    let url = ''
    if (params.map_id == '') {
        url = `${HTTP_PREFIX}/manage/search_base_maps?unit=${params.unit}`
    } else {
        url = `${HTTP_PREFIX}/manage/search_base_maps/?map_id=${params.map_id}`
    }
    const result = await axios.get(url)
    return result.data
}
export const OrthophotoUploadData = async function (body) {
    const url = `${HTTP_PREFIX}/manage/update_base_map`
    const result = await axios.post(url, body)
    return result.data
}
export const OrthophotoPublish = async function (body) {
    const url = `${HTTP_PREFIX}/manage/update_base_map`
    const result = await axios.get(url,body)
    return result.data
}
export const OrthophotoDelete = async function (map_id) {
    const url = `${HTTP_PREFIX}/manage/remove_base_map/${map_id}`
    const result = await axios.delete(url)
    return result.data
}

/** 矢量点图层获取模型和地址*/
export const vectorSearch = async function (pointLayerUrl){
  const pointLayer = await axios.get(pointLayerUrl)
  return pointLayer
} 

/** 查询无人机视野范围内兴趣点*/
export const getVisualPoi = async function (body){
  const url = `${HTTP_PREFIX}/labels/get_visual_poi`
  const result = await axios.post(url,body)
  return result.data
}

/** 查询最近无人机*/
export const getNearestUav = async function (body){
  const url = `${HTTP_PREFIX}/devices/get_nearest_uav`
  const result = await axios.post(url,body)
  return result.data
}